<?php

namespace app\demo\controller\form\field;

use yunj\Controller;

class Tree extends Controller {

    public function index() {
        $builder = YF('form_field_demo')
            ->tab(['base' => '基础'])
            ->field(function ($tab) {
                $nodes = [
                    ["id" => 0, "pid" => -1, "name" => "顶级分类", "level" => 0],
                ];
                $field = [
                    "test" => [
                        "type" => "tree",
                        "title" => "分类",
                        "mode" => "radio",
                        "nodes" => $nodes,
                        "value" => 0,
                    ],
                ];
                return $field;
            })
            ->button(['reset', 'submit'])
            ->submit(function ($data, $tab_data) {
                dump($data);
                dump($tab_data);
            });
        $builder->assign($this);
        return $this->fetch("demo@form/field_demo");
    }

}